package com.chuyu.cy.exception;

import com.chuyu.cy.contants.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 周小白
 */
@Slf4j
@ControllerAdvice(annotations = {ControllerAdvice.class, RestController.class})
@ResponseBody
public class GlobalException {

    @ExceptionHandler(value = CustomException.class)
    public Result<String> globalException(Exception e) {
        log.error("系统异常", e);
        return new Result<String>().failure(e.getMessage());
    }
}
